package com.example.demo.service;

import java.util.HashMap;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.example.demo.entity.User;
import com.example.demo.mapper.UserMapper;

@Service
public class UserService extends ServiceImpl<UserMapper, User> {
    @Autowired
    private UserMapper userMapper;

    public Map<String,Object> list(int current, int size){
        IPage<User> page = new Page<>(current, size);
        this.page(page, new QueryWrapper<User>().orderByDesc("id"));

        Map<String, Object> data = new HashMap<>();
        data.put("total", page.getTotal());
        data.put("list", page.getRecords());
        return data;
    }
    public User selectByUsername(String username) {
        return userMapper.selectByUsername(username);
    }
}